/*!
\copyright  Copyright (c) 2025 Qualcomm Technologies International, Ltd.
            All Rights Reserved.
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\version    
\file       fast_pair_l2cap.h
\brief      File consists of function declaration for Fast Pair Service's L2CAP transport.
*/
#ifndef FASTPAIR_L2CAP_H
#define FASTPAIR_L2CAP_H

#include <l2cap_manager.h>
#include <stream.h>
#include <stdlib.h>

#define FASTPAIR_LE_L2CAP_CREDIT_MAX_MTU           250
#define FASTPAIR_LE_L2CAP_CREDIT_INITIAL_CREDITS   1

/*! \brief Maximum Fast Pair LE L2CAP connections allowed */
#define FASTPAIR_LE_L2CAP_CONNECTIONS_MAX          2

/*! \brief Fast Pair LE L2CAP credit PSM value range min  */
#define FASTPAIR_LE_L2CAP_CREDIT_PSM_VALUE_MIN (0x80)

/*! \brief Fast Pair LE L2CAP credit PSM value range max  */
#define FASTPAIR_LE_L2CAP_CREDIT_PSM_VALUE_MAX (0xFF)

/*! \brief Valid range for the Message Stream PSM */
#define FASTPAIR_LE_L2CAP_CREDIT_IS_VALID_PSM(psm) (((psm) > FASTPAIR_LE_L2CAP_CREDIT_PSM_VALUE_MIN) && ((psm) < FASTPAIR_LE_L2CAP_CREDIT_PSM_VALUE_MAX))

/*! \brief State for the remote device. */
typedef enum
{
    fast_pair_le_l2cap_message_stream_state_unknown = 0x00,             /*! Fast Pair Seeker will retry for several times */
    fast_pair_le_l2cap_message_stream_state_ready_to_connect = 0x01,    /*! Ready to connect */
    fast_pair_le_l2cap_message_stream_state_unavailable = 0x02,         /*! Fast Pair Seeker won't use this component to connect this time */
} fast_pair_le_l2cap_message_stream_state_t;

/*! \brief Create the Fast Pair LE L2CAP instance and registers PSM with LE L2CAP.
    \param connection_id GATT Connection ID of the remote device.

    \return Return TRUE if Registered the PSM for LE L2CAP, FALSE otherwise.
*/
bool FastpairLeL2cap_Create(uint32 connection_id);

/*! \brief Get the Message Stream PSM value assigned to the connected remote device.
    \param connection_id GATT Connection ID of the remote device.

    \return Return the PSM value assigned to the remote device by application.
*/
uint16 FastPairLeL2Cap_GetMessageStreamPsm(uint32 connection_id);

/*! \brief Get the Message Stream State.
    \param connection_id GATT Connection ID of the remote device.

    \return Return the Message Stream State which will be used by remote device.
*/
fast_pair_le_l2cap_message_stream_state_t FastPairLeL2Cap_GetMessageStreamState(uint32 connection_id);

/*! \brief Initialise the Fast Pair LE L2CAP module.
*/
void FastPairLeL2cap_Init(void);
#endif /* FASTPAIR_L2CAP_H */

